package com.beimihu.leetcode;

public class MaximalSquare {
    public int maximalSquare(char[][] matrix) {
        int n = matrix.length;
        int[][] dp = new int[n][n];
        int res = 0;

        for(int i = 0 ; i < n;i++ ){
            for(int j = 0; j < n ; j++){
                if(matrix[i][j] == '1'){
                    if(i == 0 || j ==0) {
                        dp[i][j] = 1;
                    }
                    else{
                        dp[i][j] = Math.min(Math.min(dp[i-1][j-1],dp[i-1][j]),dp[i][j-1]) + 1;
                    }
                }
                res = Math.max(res,dp[i][j]);
            }
        }
        return res;

    }
}
